package cn.itwangxiang.android.ui;

import cn.itwangxiang.android.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class DemoUITab extends TabActivity implements OnCheckedChangeListener {
	private RadioGroup mainTab;
	private TabHost tabhost;
	
	private Intent iHome;
	private Intent iNews;
	private Intent iInfo;
	private Intent iSearch;
	private Intent iMore;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.demo_ui_tab);
		mainTab = (RadioGroup) findViewById(R.id.main_tab);
		mainTab.setOnCheckedChangeListener(this);

		prepareIntent();

		initView();
	}

	/**
	 * 准备tab的内容Intent
	 */
	private void prepareIntent() {
		
		iHome = new Intent(this, DemoUIText.class);
		iNews = new Intent(this, DemoLayoutLinear.class);
		iInfo = new Intent(this, DemoLayoutRelative.class);
		iSearch = new Intent(this, DemoLayoutTable.class);
		iMore = new Intent(this, DemoLayoutFrame.class);
		
	}

	private void initView() {

		tabhost = getTabHost();

		tabhost.addTab(tabhost
				.newTabSpec("iHome")
				.setIndicator(getResources().getString(R.string.main_home),
						getResources().getDrawable(R.drawable.icon_1_n))
				.setContent(iHome));

		tabhost.addTab(tabhost
				.newTabSpec("iNews")
				.setIndicator(getResources().getString(R.string.main_news),
						getResources().getDrawable(R.drawable.icon_2_n))
				.setContent(iNews));

		tabhost.addTab(tabhost
				.newTabSpec("iInfo")
				.setIndicator(getResources().getString(R.string.main_my_info),
						getResources().getDrawable(R.drawable.icon_3_n))
				.setContent(iInfo));

		tabhost.addTab(tabhost
				.newTabSpec("iSearch")
				.setIndicator(getResources().getString(R.string.menu_search),
						getResources().getDrawable(R.drawable.icon_4_n))
				.setContent(iSearch));

		tabhost.addTab(tabhost
				.newTabSpec("iMore")
				.setIndicator(getResources().getString(R.string.more),
						getResources().getDrawable(R.drawable.icon_5_n))
				.setContent(iMore));
	}
	
	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		
		switch (checkedId) {
		case R.id.radio_button0:
			tabhost.setCurrentTabByTag("iHome");
			break;
		case R.id.radio_button1:
			tabhost.setCurrentTabByTag("iNews");
			break;
		case R.id.radio_button2:
			tabhost.setCurrentTabByTag("iInfo");
			break;
		case R.id.radio_button3:
			tabhost.setCurrentTabByTag("iSearch");
			break;
		case R.id.radio_button4:
			tabhost.setCurrentTabByTag("iMore");
			break;
		}
	}
}
